<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <el-form :model="where" class="ele-form-search" label-width="auto" @keyup.enter.native="reload" @submit.native.prevent>
        <el-row :gutter="15">
          <el-col :lg="6" :md="12">
            <el-form-item label="人员名称：">
              <el-select
                v-model="where.user_id"
                filterable
                remote
                clearable
                reserve-keyword
                placeholder="请搜索人员名称"
                :remote-method="remoteMethod"
                :loading="loading">
                <el-option
                  v-for="item in options"
                  :key="item.id"
                  :label="item.realname"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="12">
            <el-form-item label="部门：">
              <el-select v-model="where.dept_id" placeholder="请选择部门">
                <el-option
                  v-for="item in options2"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="12">
            <div class="ele-form-actions">
              <el-button v-if="permission.includes('sys:qr_code:index')" class="ele-btn-icon" icon="el-icon-search" type="primary" @click="reload">
                查询
              </el-button>
              <el-button @click="reset">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
      <!-- 数据表格 -->
      <ele-pro-table ref="table" :columns="columns" :datasource="url" :selection.sync="selection" :where="where" height="calc(100vh - 315px)"></ele-pro-table>
    </el-card>
  </div>
</template>

<script>
import { mapGetters } from "vuex";

export default {
  name: 'SystemLevel',
  computed: {
    ...mapGetters(["permission"]),
  },
  data() {
    return {
      options:[],
      loading:false,
      options2:[],
      flag: false,
      // 表格数据接口
      url: '/reports/person_work_order',
      // 表格列配置
      columns: [
        // {
        //   columnKey: 'selection',
        //   type: 'selection',
        //   width: 45,
        //   align: 'center',
        //   fixed: "left"
        // },
        {
          prop: 'user_name',
          label: '人员',
          width: 150,
          align: 'center',
          showOverflowTooltip: true,
        },
        {
          prop: 'un_complete_count',
          label: '未完成',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center',
        },
        {
          prop: 'today_complete_count',
          label: '今日完成',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center',
        },
        {
          prop: 'week_complete_count',
          label: '本周完成',
          showOverflowTooltip: true,
          minWidth: 150,
          align: 'center',
        },
        {
          prop: 'month_complete_count',
          label: '本月完成',
          showOverflowTooltip: true,
          minWidth: 160,
          align: 'center'
        },
        {
          prop: 'good_review_count',
          label: '客户好评',
          showOverflowTooltip: true,
          minWidth: 150,
          align: 'center',
        },
        {
          prop: 'bad_review_count',
          label: '客户差评',
          showOverflowTooltip: true,
          minWidth: 150,
          align: 'center',
        }
      ],
      // 表格搜索条件
      where: {},
      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null
    };
  },
  methods: {
    /*搜索人员*/
    remoteMethod(query) {
      if (query !== '') {
        this.loading = true;
        this.$http.get(`/user/index?limit=10&realname=${query} `).then((res) => {
          this.options=res.data.data.filter(item => {
            return item.id !== 1
          });
          this.loading = false;
        });
      } else {
        this.options = [];
        this.loading = false;
      }
    },
    getParams(){
      this.$http.get('dept/index').then(res => {
        if (res.data.code === 0) {
          this.options2=res.data.data
        } else {
          this.$message.error(res.data.msg);
        }
      })
    },
    /* 刷新表格 */
    reload() {
      this.$refs.table.reload({ where: this.where });
    },
    /* 重置搜索 */
    reset() {
      this.where = {};
      this.reload();
    }
  },
  mounted() {
    this.getParams()
  },
}
</script>

<style scoped>
.el-select{
  width: 100%;
}
</style>
